﻿<Window x:Class="HBCode.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
        xmlns:AvalonDockMVVM="clr-namespace:AvalonDockMVVM;assembly=AvalonDockMVVM"
        xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
        xmlns:viewmodel="clr-namespace:HBCode.Presentation;assembly=HBCode.Presentation"
        xmlns:views="clr-namespace:HBCode.Views"
        xmlns:converter="clr-namespace:HBCode.Converters"
        xmlns:wpfextended="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
        xmlns:wpftoolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
        Title="HB Code - WPF / MVVM / Entity Framework"
        WindowStartupLocation="CenterScreen"
        WindowState="Maximized" Icon="Images/HBIcon.jpg"
        Height="800" Width="1024">
    <Window.Resources>
        <converter:ResourceConverter x:Key="resourceConverter" />
        <ControlTemplate x:Key="ErrorMessageTemplate">
            <DockPanel LastChildFill="True">
                <TextBlock Margin="1 2 0 0"
                           DockPanel.Dock="Right"
                           FontSize="20"
                           Foreground="Red"
                           VerticalAlignment="Center"
                           ToolTip="{Binding ElementName=controlWithError,
                                             Path=AdornedElement.(Validation.Errors)[0].ErrorContent,
                                             Converter={StaticResource resourceConverter},
                                             IsAsync=True}">
                    <TextBlock.Triggers>
                        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                            <BeginStoryboard>
                                <Storyboard AutoReverse="True" RepeatBehavior="Forever">
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetName="imgError" Storyboard.TargetProperty="(UIElement.Opacity)">
                                        <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.1" />
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </TextBlock.Triggers>
                    <Image x:Name="imgError"
                           Width="18"
                           Height="18"
                           Source="Images/error.png" />
                </TextBlock>
                <Border BorderBrush="Red" BorderThickness="1.5">
                    <AdornedElementPlaceholder Name="controlWithError" />
                </Border>
            </DockPanel>
        </ControlTemplate>
        
        <DataTemplate DataType="{x:Type viewmodel:CustomerViewModel}">
            <ad:DockableContent Title="{Binding DisplayName}">
                <views:CustomersView DataContext="{Binding IsAsync=True}" />
            </ad:DockableContent>
        </DataTemplate>
        
        <Style TargetType="TextBox">
            <Setter Property="Validation.ErrorTemplate" Value="{DynamicResource ErrorMessageTemplate}" />
        </Style>
        <Style TargetType="{x:Type wpftoolkit:DatePicker}">
            <Setter Property="Validation.ErrorTemplate" Value="{DynamicResource ErrorMessageTemplate}" />
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <ribbon:Ribbon Grid.Row="0">
            <ribbon:RibbonTab Header="{DynamicResource CustomerViewModel}">
                <ribbon:RibbonGroup>
                    <ribbon:RibbonButton Command="{Binding ModuleCommand}"
                                         CommandParameter="Customer"
                                         Label="{DynamicResource CustomerViewModel}"
                                         LargeImageSource="Images/customer-large.png"
                                         SmallImageSource="Images/customer-small.png" />
                </ribbon:RibbonGroup>
                <ribbon:RibbonGroup x:Name="rbnHomecontextGroup"
                                              Header="{DynamicResource CallActions}"
                                              Style="{DynamicResource ribbonContextualRibbonGroup}">
                    <ribbon:RibbonButton x:Name="rbAddNew"
                                                 Label="{DynamicResource New}"
                                                 Command="{Binding ActiveChildViewModel.AddNewCommand}"
                                                 LargeImageSource="Images/new.png"
                                                 SmallImageSource="Images/new.png"
                                                 Style="{DynamicResource ribbonButtonTool}" />
                    <ribbon:RibbonButton x:Name="rbDelete"
                                                 Label="{DynamicResource Delete}"
                                                 Command="{Binding ActiveChildViewModel.DeleteCommand}"
                                                 LargeImageSource="Images/delete.png"
                                                 SmallImageSource="Images/delete.png"
                                                 Style="{DynamicResource ribbonButtonTool}" />
                    <ribbon:RibbonButton x:Name="rbSave"
                                                 Label="{DynamicResource Save}"
                                                 Command="{Binding ActiveChildViewModel.SaveCommand}"
                                                 LargeImageSource="Images/save.png"
                                                 SmallImageSource="Images/save.png"
                                                 Style="{DynamicResource ribbonButtonTool}" />
                    <ribbon:RibbonButton x:Name="rbCancel"
                                                 Label="{DynamicResource Cancel}"
                                                 Command="{Binding ActiveChildViewModel.CancelCommand}"
                                                 LargeImageSource="Images/cancel-large.png"
                                                 SmallImageSource="Images/cancel-small.png"
                                                 Style="{DynamicResource ribbonButtonTool}" />
                </ribbon:RibbonGroup>
            </ribbon:RibbonTab>

        </ribbon:Ribbon>

        <AvalonDockMVVM:AvalonDockHost x:Name="avalonDockHost"
                                       Grid.Row="1"
                                       ActivePane="{Binding ActiveViewModel, IsAsync=True}"
                                       AvalonDockLoaded="avalonDockHost_AvalonDockLoaded"
                                       Panes="{Binding ViewModelItems, IsAsync=True}" DocumentClosing="avalonDockHost_DocumentClosing" />
        <!--<wpfextended:BusyIndicator IsBusy="{Binding IsBusy, IsAsync=True}">
        </wpfextended:BusyIndicator>-->
    </Grid>
</Window>
